# required for websocket support
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 80;
    server_name funk.apiote.xyz;

    root /frontend;

    add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; object-src 'none'; media-src 'self' data:";
    add_header Referrer-Policy "strict-origin-when-cross-origin";
    add_header X-Frame-Options "SAMEORIGIN" always;

    location / {
        include /etc/nginx/conf.d/proxy.inc;
        client_max_body_size 100M;
        proxy_pass   http://funk:5000/;
    }

    location /front/ {
        add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; object-src 'none'; media-src 'self' data:";
        add_header Referrer-Policy "strict-origin-when-cross-origin";
        add_header Service-Worker-Allowed "/";
        alias /srv/funk/frontend/;
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

    location /front/embed.html {
        add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; object-src 'none'; media-src 'self' data:";
        add_header Referrer-Policy "strict-origin-when-cross-origin";

        add_header X-Frame-Options "" always;
        alias /srv/funk/frontend/embed.html;
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

    location /federation/ {
        include /etc/nginx/conf.d/proxy.inc;
        proxy_pass   http://funk:5000/federation/;
    }

    location /rest/ {
        include /etc/nginx/conf.d/proxy.inc;
        proxy_pass   http://funk:5000/api/subsonic/rest/;
    }

    location /.well-known/ {
        include /etc/nginx/conf.d/proxy.inc;
        proxy_pass   http://funk:5000/.well-known/;
    }

    location /media/ {
        alias /srv/funk/media/;
    }

    location /_protected/media {
        internal;
        alias   /srv/funk/media;

    }

    location /_protected/music {
        internal;
        alias   /srv/funk/music;
    }

    location /staticfiles/ {
        alias /srv/funk/static/;
    }
}
